#include "StdAfx.h"
#include "TG_AnchorNetSDK.h"

#include "TGSvrNetMan.h"

UINT32 __stdcall TG_NetClient_GetSdkVersion()
{
	return 0;
}

TGERR_CODE __stdcall TG_NetClient_Init(TGHANDLE &hAncNet)
{
	TGSvrNetMan *pSvrNet = new TGSvrNetMan();
	if( NULL == pSvrNet )
	{
		return TG_ERR_FAILURE;
	}

    hAncNet = (TGHANDLE)pSvrNet;

	return TG_ERR_SUCCESS;
}

TGERR_CODE __stdcall TG_NetClient_Cleanup(TGHANDLE hAncNet)
{
	TGSvrNetMan *pSvrNet = (TGSvrNetMan *)hAncNet;
	if( NULL == pSvrNet )
	{
		return TG_ERR_PARAMETER_ERROR;
	}

	delete pSvrNet;
	pSvrNet = NULL;

	return TG_ERR_SUCCESS;
}



TGSVRNET_API TGERR_CODE __stdcall TG_NetClient_Login(HANDLE hAncNet,TG_CONNECT_INFO *pChatInfo)
{
	TGSvrNetMan *pSvrNet = (TGSvrNetMan *)hAncNet;
	if( NULL == pSvrNet )
	{
		return TG_ERR_PARAMETER_ERROR;
	}
	return pSvrNet->Login(pChatInfo);
}
TGSVRNET_API TGERR_CODE __stdcall TG_NetClient_Logoff(HANDLE hAncNet)
{
	TGSvrNetMan *pSvrNet = (TGSvrNetMan *)hAncNet;
	if( NULL == pSvrNet )
	{
		return TG_ERR_PARAMETER_ERROR;
	}
	pSvrNet->Logoff();
	return TG_ERR_SUCCESS;
}
TGERR_CODE __stdcall TG_NetClient_SetConnectTime(TGHANDLE hAncNet,UINT32 nWaitTime, UINT32 nTryTimes)
{
	TGSvrNetMan *pSvrNet = (TGSvrNetMan *)hAncNet;
	if( NULL == pSvrNet )
	{
		return TG_ERR_PARAMETER_ERROR;
	}

	return (TGERR_CODE)pSvrNet->SetConnectTime(nWaitTime,nTryTimes);
}

TGERR_CODE __stdcall TG_SvrNet_SetListen(TGHANDLE hAncNet,SINT8 *pszIP,UINT16 nCmdPort, UINT16 nDataPort)
{
	TGSvrNetMan *pSvrNet = (TGSvrNetMan *)hAncNet;
	if( NULL == pSvrNet )
	{
		return TG_ERR_PARAMETER_ERROR;
	}

	return (TGERR_CODE)pSvrNet->SetListen(pszIP,nCmdPort,nDataPort);
}



TGERR_CODE __stdcall TG_SvrNet_RegCheckUserCallBack(TGHANDLE hAncNet,SvrNetCheckUserCBFun funCallBack,VOID *pContext)
{
	TGSvrNetMan *pSvrNet = (TGSvrNetMan *)hAncNet;
	if( NULL == pSvrNet )
	{
		return TG_ERR_PARAMETER_ERROR;
	}

	return (TGERR_CODE)pSvrNet->RegCheckUserCallBack(funCallBack,pContext);
}



TGERR_CODE __stdcall TG_SvrNet_RegSetConfigCallBack(TGHANDLE hAncNet,SvrNetSetConfigCBFun funCallBack,VOID *pContext)
{
	TGSvrNetMan *pSvrNet = (TGSvrNetMan *)hAncNet;
	if( NULL == pSvrNet )
	{
		return TG_ERR_PARAMETER_ERROR;
	}

	return (TGERR_CODE)pSvrNet->RegSetConfigCallBack(funCallBack,pContext);
}

TGERR_CODE __stdcall TG_SvrNet_RegGetConfigCallBack(TGHANDLE hAncNet,SvrNetGetConfigCBFun funCallBack,VOID *pContext)
{
	TGSvrNetMan *pSvrNet = (TGSvrNetMan *)hAncNet;
	if( NULL == pSvrNet )
	{
		return TG_ERR_PARAMETER_ERROR;
	}

	return (TGERR_CODE)pSvrNet->RegGetConfigCallBack(funCallBack,pContext);
}


TGERR_CODE __stdcall TG_SvrNet_RegRealStreamCallBack(TGHANDLE hAncNet,SvrNetRealStreamCBFun funCallBack,VOID *pContext)
{
	TGSvrNetMan *pSvrNet = (TGSvrNetMan *)hAncNet;
	if( NULL == pSvrNet )
	{
		return TG_ERR_PARAMETER_ERROR;
	}

	return (TGERR_CODE)pSvrNet->RegRealStreamCallBack(funCallBack,pContext);
}

TGERR_CODE __stdcall TG_SvrNet_RegRealStreamItemCallBack(TGHANDLE hAncNet,SvrNetRealStreamItemCBFun funCallBack,VOID *pContext)
{
	TGSvrNetMan *pSvrNet = (TGSvrNetMan *)hAncNet;
	if( NULL == pSvrNet )
	{
		return TG_ERR_PARAMETER_ERROR;
	}

	return (TGERR_CODE)pSvrNet->RegRealStreamItemCallBack(funCallBack,pContext);
}



TGERR_CODE __stdcall TG_SvrNet_Start(TGHANDLE hAncNet)
{
	TGSvrNetMan *pSvrNet = (TGSvrNetMan *)hAncNet;
	if( NULL == pSvrNet )
	{
		return TG_ERR_PARAMETER_ERROR;
	}

	return (TGERR_CODE)pSvrNet->SvrStart();
}

TGERR_CODE __stdcall TG_SvrNet_Stop(TGHANDLE hAncNet)
{
	TGSvrNetMan *pSvrNet = (TGSvrNetMan *)hAncNet;
	if( NULL == pSvrNet )
	{
		return TG_ERR_PARAMETER_ERROR;
	}

	return (TGERR_CODE)pSvrNet->SvrStop();
}


TGERR_CODE __stdcall TG_SvrNet_RemoveCamera(TGHANDLE hAncNet,TG_DEV_INFO *pDevInfo)
{
	TGSvrNetMan *pSvrNet = (TGSvrNetMan *)hAncNet;
	if( NULL == pSvrNet )
	{
		return TG_ERR_PARAMETER_ERROR;
	}

	return (TGERR_CODE)pSvrNet->m_xRealStreamMan.RemoveCamera(pDevInfo);
}

TGERR_CODE __stdcall TG_SvrNet_RemoveCameraItem(TGHANDLE hCamera,TGHANDLE hItem)
{
	SvrNetRPCamera *pCamera = (SvrNetRPCamera*)hCamera;
	if( NULL == pCamera )
	{
		return TG_ERR_PARAMETER_ERROR;
	}

	return (TGERR_CODE)pCamera->RemoveItem(hItem);
}

TGERR_CODE __stdcall TG_SvrNet_GetCameraItemCount(TGHANDLE hCamera,UINT32 &nCount)
{
	SvrNetRPCamera *pCamera = (SvrNetRPCamera*)hCamera;
	if( NULL == pCamera )
	{
		return TG_ERR_PARAMETER_ERROR;
	}

	return (TGERR_CODE)pCamera->GetItemCount(nCount);
}


TGERR_CODE __stdcall TG_NetClient_SetRealStreamFrame(TGHANDLE hAncNet,VOID *pFrame,UINT32 lFrameSize)
{
	TGSvrNetMan *pSvrNet = (TGSvrNetMan *)hAncNet;
	if( NULL == pSvrNet->m_pNetRPCamera )
	{
		return TG_ERR_PARAMETER_ERROR;
	}
	return (TGERR_CODE)pSvrNet->m_pNetRPCamera->SetFrame(pFrame,lFrameSize);
}


TGERR_CODE __stdcall TG_SvrNet_RemoveCameraItem2(TGHANDLE hAncNet,UINT16 nCameraPos,TGHANDLE hCamera,TGHANDLE hItem)
{
	TGSvrNetMan *pSvrNet = (TGSvrNetMan *)hAncNet;
	if( NULL == pSvrNet )
	{
		return TG_ERR_PARAMETER_ERROR;
	}

	return (TGERR_CODE)pSvrNet->m_xRealStreamMan.RemoveCameraItem2(nCameraPos,hCamera,hItem);
}

TGERR_CODE __stdcall TG_SvrNet_GetCameraItemCount2(TGHANDLE hAncNet,UINT16 nCameraPos,TGHANDLE hCamera,UINT32 &nCount)
{
	TGSvrNetMan *pSvrNet = (TGSvrNetMan *)hAncNet;
	if( NULL == pSvrNet )
	{
		return TG_ERR_PARAMETER_ERROR;
	}

	return (TGERR_CODE)pSvrNet->m_xRealStreamMan.GetCameraItemCount2(nCameraPos,hCamera,nCount);
}

TGERR_CODE __stdcall TG_SvrNet_SetRealStreamFrame2(TGHANDLE hAncNet,UINT16 nCameraPos,TGHANDLE hCamera,VOID *pFrame,UINT32 lFrameSize)
{
	TGSvrNetMan *pSvrNet = (TGSvrNetMan *)hAncNet;
	if( NULL == pSvrNet )
	{
		return TG_ERR_PARAMETER_ERROR;
	}

	return (TGERR_CODE)pSvrNet->m_xRealStreamMan.SetRealStreamFrame2(nCameraPos,hCamera,pFrame,lFrameSize);
}
